﻿using System;

namespace Avivo.Tools
{
	public class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine("IIS https binding utility 0.7");
			Console.WriteLine();

			if (args == null || args.Length != 2)
			{
				Console.WriteLine("Description:");
				Console.WriteLine("  Registers 'http' and 'https' bindings for a web site on IIS 7");
				Console.WriteLine();
				Console.WriteLine("Usage:");
				Console.WriteLine("  iisman [site-name] [domain-name]");
				Console.WriteLine();
				Console.WriteLine("Example:");
				Console.WriteLine("  iisman my-domain www.my-domain.com");
				Console.WriteLine("  iisman my-domain.com admin.my-domain.com");
				Console.WriteLine("  iisman \"My Web Site\" \"www.my-domain.com\"");
				Console.WriteLine();
				Console.WriteLine("Notes:");
				Console.WriteLine("  To delete bindings open IIS Manager (inetmgr), right click on a web site,");
				Console.WriteLine("  select 'Edit Bindings...', select bindings and click 'Delete'.");
			}
			else
			{
				var color = Console.ForegroundColor;

				try
				{
					//Example: IISHelper.Register("My Web Site", "www.my-domain.com");
					IISHelper.Register(args[0], args[1]);
					Console.WriteLine("Successfully completed!");
				}
				catch (Exception ex)
				{
					Console.ForegroundColor = ConsoleColor.Red;
					Console.WriteLine(ex.Message);
					Console.WriteLine(ex.StackTrace);
				}

				Console.ForegroundColor = color;
			}
		}
	}
}
